<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/Home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/Cost' }">费用类目</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/OtherCost' }">其他收付款</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/DischargeSettlement' }">出院结算</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/OccupancyFee' }">入住缴费</el-breadcrumb-item>
    </el-breadcrumb>
    <el-row :gutter="20">
      <el-col :span="4">
        <el-button type="primary" @click="openAddDialog">创建入住缴费信息</el-button>
      </el-col>


      <el-col :span="5" label="状态" >
        <el-select v-model="status" @change="searchByStatus" placeholder="请选择状态">
          <el-option  key="-1" label="请选择" value="-1"></el-option>
          <el-option key="1"  label="已扣费" value="1"></el-option>
          <el-option key="0"  label="已作废" value="0"></el-option>
        </el-select>
      </el-col>
        <el-date-picker
            v-model="dateInterval"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
        </el-date-picker>
      <el-col :span="5">
      <el-input placeholder="请输入长者姓名" clearable v-model="oldername" @clear="search">
        <el-button slot="append" icon="el-icon-search" @click="search"></el-button>
      </el-input>
    </el-col>
    </el-row>


    <!--展示-->
    <div>
      <template>
        <el-table
            :data="deliveryvoList"
            style="width: 100%"
            :row-class-name="tableRowClassName">
          <el-table-column prop="id" label="#" width="40px"></el-table-column>
          <el-table-column prop="older.name" label="长者姓名" width="90px"></el-table-column>
          <el-table-column prop=".older.idcard" label="长者身份证号" width="180px"></el-table-column>
          <el-table-column prop="iccard" label="扣费卡号"></el-table-column>
          <el-table-column prop="begindate" label="开始日期"></el-table-column>
          <el-table-column prop="enddate" label="结束日期"></el-table-column>
          <el-table-column prop="totalprice" label="总金额"></el-table-column>

          <el-table-column label="状态">
            <template slot-scope="scope">
              <span v-if="scope.row.status==0">已作废</span>
              <span v-if="scope.row.status==1" style="color: #0077ff">已扣费</span>

            </template>
          </el-table-column>
          <el-table-column prop="description" label="说明"></el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
<!--              <el-button-->
<!--                  style="margin-left: 10px"-->
<!--                  size="mini"-->
<!--                  type="success"-->
<!--                  @click="searchDetail(scope.row)">查看-->
<!--              </el-button>-->
              <el-button
                  v-if="scope.row.status==1"
                  style="margin-top: 5px"
                  size="mini"
                  type="danger"
                  @click="cancelDelivery(scope.row.id)">作废
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>

      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="pagelist"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
      ></el-pagination>
    </div>
    <div>
      <template>
        <div>

          <!-- IC卡信息对话框 -->
          <el-dialog
              width="75%"
              title="选择卡号信息"
              :visible.sync="innerVisible"
          >

            <el-input placeholder="请输入长者姓名或卡号" clearable v-model="cardName" @clear="search" style="width: 300px;margin-left: 300px">
              <el-button slot="append" icon="el-icon-search" @click="initCardList"></el-button>
            </el-input>

            <template>
              <el-table
                  :data="CardList"
                  style="width: 500px;text-align: center;margin-left: 200px"
                  :row-class-name="tableRowClassName"
                  :close-on-click-modal="false"
              >
                <el-table-column
                    label="卡号"
                    prop="number"
                    width="60">
                </el-table-column>
                <el-table-column
                    prop="name"
                    label="长者姓名"
                    width="100">
                </el-table-column>
                <el-table-column
                    prop="balance"
                    label="余额"
                    width="100">
                </el-table-column>
                <el-table-column label="操作" width="240">
                  <template slot-scope="scope">
                    <el-button
                        size="mini"
                        v-if="scope.row.status != 0"
                        @click="selectCard(scope.row.number)">选择
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </template>
          </el-dialog>
        </div>
      </template>
    </div>

    <!-- 订单药品详情 -->
    <el-dialog
        width="75%"
        title="药品出库单"
        style="text-align: center"
        :visible.sync="detailVisible"
    >
      <el-descriptions class="margin-top" title="订单详情" :column="3" size="mini" :border="true" >
        <el-descriptions-item label="长者">{{detailoldername}}</el-descriptions-item>
        <el-descriptions-item label="订单总价">￥{{detailTotalprice}}元</el-descriptions-item>
        <el-descriptions-item label="订单编号">{{detailOrdernum}}</el-descriptions-item>
      </el-descriptions>
      <hr>
      <el-table
          :data="detailList"
          style="width: 100%"
          :row-class-name="tableRowClassName">
        <el-table-column prop="id" label="#" width="30px"></el-table-column>
        <el-table-column prop="medicine.drugnum" label="药品编号"></el-table-column>
        <el-table-column prop="medicine.drugname" label="药品名称"></el-table-column>
        <el-table-column prop="medicine.specification" label="规格"></el-table-column>
        <el-table-column prop="medicine.unit" label="单位"></el-table-column>
        <el-table-column prop="count" label="数量"></el-table-column>
        <el-table-column prop="medicine.saleprice" label="销售价（元）"></el-table-column>
        <el-table-column prop="sumPrice" label="金额（元）"></el-table-column>
        <el-table-column prop="desc" label="备注"></el-table-column>
        <el-table-column prop="createtime" label="购买日期"></el-table-column>
      </el-table>
    </el-dialog>


    <!--创建药品出库订单-->

    <el-dialog title="添加入院消费" :visible.sync="addDeliveryFormVisible"  @close="closeAddDeliverForm" :close-on-click-modal="false" width="80%">
      <div style="width: 50%;display: inline-block">
        <el-form ref="addDeliveryFormRef" :rules="addDeliveryFormRules" :model="addDeliveryForm" label-width="100px"  style="margin-left: 10px;width: 100%">
<!--          <el-form-item label="长者" prop="olderName" @click="innerVisible = true">-->
<!--            <el-button v-model="addDeliveryForm.olderName" style="width: 80px;height: 30px;line-height: 10px" type="danger" @click="innerVisible = true">-->
<!--              {{ addDeliveryForm.olderName }}-->
<!--            </el-button>-->
<!--          </el-form-item>-->
          <el-form-item label="长者" prop="olderId">
            <el-button style="margin-left: 15px" type="primary" v-model="addDeliveryForm.olderId" @click="innerOlderVisible = true" >{{ addDeliveryForm.olderName }}</el-button>
          </el-form-item>
          <el-form-item label="IC卡" prop="number">
            <el-select size="small" @change="handleChangeICCard(ICCard.number)" v-model="ICCard.number" placeholder="请选择IC卡">
              <el-option v-for="t in ICCard" :label="t.number" :value="t.id"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="IC卡余额" >
            <el-input   v-model="balance" disabled style="margin-bottom: 10px;width: 200px"></el-input>
          </el-form-item>

          <el-form-item label="时间段" prop="time" >
            <el-date-picker
                v-model="addDeliveryForm.time"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="总价" prop="totalprice">
            <el-input disabled v-model="addDeliveryForm.totalprice" style="width: 200px"></el-input>
          </el-form-item>
          <el-form-item label="订单备注" prop="description">
            <el-input type="textarea" v-model="addDeliveryForm.description" style="width: 80%"></el-input>
          </el-form-item>
          <el-form-item label="其他扣费项" prop="deliveryDetailVos">
            <el-button type="warning" @click="innerDrugVisible=true">选择其他扣费项目</el-button>

          </el-form-item>
        </el-form>
      </div>
      <div style="width: 50%;display: inline-block;">
        <h3>基本收款项</h3>
        <el-table
            style="width:1500px"
            :data="costPay"
            :row-class-name="tableRowClassName"
        >
          <el-table-column
              label="#"
              type="index"
              width="50">
          </el-table-column>
          <el-table-column prop="category" label="类目名称" ></el-table-column>
          <el-table-column prop="price" label="收费金额"></el-table-column>
          <el-table-column prop="price" label="实收金额"></el-table-column>
        </el-table>
        <h3 style="padding-top: 40px">其他收款项</h3>
        <el-table
            style="width:1500px;"
            :data="selectDrugList"
            :row-class-name="tableRowClassName"
        >
          <el-table-column
              label="#"
              type="index"
              width="50">
          </el-table-column>
          <el-table-column prop="category" label="类目名称" ></el-table-column>
          <el-table-column prop="price" label="收费金额"></el-table-column>
          <el-table-column prop="price" label="实收金额"></el-table-column>
          <el-table-column label="操作" width="90">
            <template slot-scope="scope">
              <el-button
                  size="mini"
                  type="primary"
                  @click="cancelSelect(scope.row.id)">删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button  @click="closeAddDeliverForm">取 消</el-button>
        <el-button type="primary" @click="addDeliver">确 定</el-button>
      </div>
    </el-dialog>



    <!--药品信息对话框-->
    <el-dialog
        width="90%"
        title="其他收付款信息"
        :visible.sync="innerDrugVisible"
        append-to-body>
      <div>
        <template>
          <el-table
              :data="drugList"
              style="width: 100%"
              :row-class-name="tableRowClassName">
            <el-table-column prop="id" label="#" width="30px"></el-table-column>
            <el-table-column prop="category" label="项目名"></el-table-column>
            <el-table-column prop="price" label="价格"></el-table-column>
            <el-table-column prop="date" label="活动日期"></el-table-column>
            <el-table-column prop="notes" label="备注"></el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button
                    style="margin-left: 10px"
                    size="mini"
                    type="success"
                    @click="selectDrug(scope.row)">选择
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </template>

        <el-pagination
            @size-change="drugHandleSizeChange"
            @current-change="drugHandleCurrentChange"
            :current-page="drugpageNum"
            :page-sizes="drugpagelist"
            :page-size="drugpageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="drugtotal"
        ></el-pagination>
      </div>
    </el-dialog>

    <!-- 长者信息对话框 -->
    <el-dialog
        width="75%"
        title="选择长者信息"
        :visible.sync="innerOlderVisible"
        append-to-body>
      <el-input placeholder="请输入长者姓名" clearable v-model="olderName" @clear="searchOlder">
        <el-button slot="append" icon="el-icon-search" @click="searchOlder"></el-button>
      </el-input>
      <el-pagination
          @size-change="olderSizeChange"
          @current-change="olderCurrentChange"
          :current-page="olderPageNum"
          :page-sizes="[3, 6 , 12, 24]"
          :page-size="olderPageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="olderTotal"
      ></el-pagination>
      <template>
        <el-table
            :data="olderList"
            style="width: 100%"
            :row-class-name="tableRowClassName"
        >
          <el-table-column
              label="编号"
              type="index"
              width="60">
          </el-table-column>
          <el-table-column
              prop="name"
              label="长者姓名"
              width="100">
          </el-table-column>
          <el-table-column
              prop="sex"
              label="性别"
              width="100">
          </el-table-column>
          <el-table-column
              prop="bed.bedname"
              label="床位号"
              width="100">
          </el-table-column>
          <el-table-column
              prop="idcard"
              label="长者身份证号"
              width="220">
          </el-table-column>
          <el-table-column
              prop="checkdate"
              label="入住日期"
              width="150">
          </el-table-column>
          <el-table-column
              label="在院状态"
              width="120"
          >
            <template slot-scope="scope">
              <span style="color: red" v-if="scope.row.status == 0">退房</span>
              <span style="color: green" v-if="scope.row.status == 1">入住</span>
              <span style="color: red" v-if="scope.row.status == 2">待退房</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="240">
            <template slot-scope="scope">
              <el-button
                  size="mini"
                  v-if="scope.row.status != 0"
                  @click="selectOlder(scope.row.id,scope.row.name)">选择
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </el-dialog>



  </div>
</template>


<script>
export default {
  name: "Delivery",
  data() {
    return {
      costPay:[],
      ICCard:[],
      balance:'',
      //搜素，分页，页面展示
      deliveryvoList: [],
      status: '',
      oldername: '',
      dateInterval:[],
      pageNum: 1,
      pageSize: 6,
      pagelist: [2, 3, 6, 8],
      total: 0,

      //查看订单详情
      detailList: [],
      detailTotalprice:0,
      detailoldername:'',
      detailOrdernum:'',
      detailVisible: false,

      //查看ic卡
      id: 0,
      pay: 0,
      CardNumber: "",
      CardList: [],
      innerVisible: false,
      cardName: '',


      //添加
      addDeliveryForm: {totalprice:0,},
      addDeliveryFormVisible: false,
      addDeliveryFormRules: {
        olderId:[{required: true, message: "不能为空", trigger: 'blur'}],
        time:[{required: true, message: "不能为空", trigger: 'blur'}],
      },
      price2:0,//代替表单总价

      //添加，编辑
      selectDrugList: [],

      //编辑
      editForm:{olderName:"",olderId:0,totalprice: 0,saletime:"",desc:'',deliveryDetailVos:[]},
      editFormVisiable:false,
      editFormRules:{
        olderName:[{required: true, message: "不能为空", trigger: 'blur'}],
        saletime:[{required: true, message: "不能为空", trigger: 'blur'}],
      },
      price3:0,

      //长者消息
      innerOlderVisible: false,
      olderList: [],
      olderName: '',
      olderId: 0,
      olderPageNum: 1,
      olderPageSize: 3,
      olderTotal: 0,
      //药品信息
      innerDrugVisible: false,
      drugList: [],
      drugname: '',
      drugpageNum: 1,
      drugpageSize: 3,
      drugpagelist: [2, 3, 6, 8],
      drugtotal: 0,

    }
  },
  methods: {
    searchByStatus() {
      this.pageNum = 1;
      this.initdeliveryVolIst();
    },
    //打开编辑对话框
    openEditDiolog(delivery){
      this.editFormVisiable=true;

      let totalprice=delivery.totalprice;
      let olderId=delivery.older.id;
      let olderName=delivery.older.name;
      let saletime=delivery.saletime;
      let desc=delivery.desc;

      this.editForm.totalprice=totalprice;
      this.editForm.olderId=olderId;
      this.editForm.olderName=olderName;
      this.editForm.saletime=saletime;
      this.editForm.desc=desc;
      this.price3=this.editForm.totalprice;
      this.editForm.ordernum=delivery.ordernum;
      this.editForm.deliveryId=delivery.id;

      /*  this.editForm.older=delivery.older;
        this.editForm.totalprice=delivery.totalprice;
        this.editForm.olderId=delivery.older.id;
        this.editForm.olderName=delivery.older.name;
        this.editForm.saletime=delivery.saletime;
        this.editForm.desc=delivery.desc;
        this.price3=delivery.totalprice;*/
      this.$axios.get("/delivery/detailById/" + delivery.id).then((res) => {
        if (res.data.code == 200) {
          this.selectDrugList = res.data.data;
        }
      })
    },
    //编辑==改变药品数量（小计和总价）
    edithandleChange(deliveryDetailVo){
      let totalprice=0;
      let price=deliveryDetailVo.medicine.saleprice;
      let count=deliveryDetailVo.count;
      let sumprice= price * count;
      for(let a of this.selectDrugList){
        if(deliveryDetailVo.medicine.id==a.medicine.id){
          a.sumPrice=sumprice;
        }

        let price1=a.medicine.saleprice;
        let count1=a.count;
        let s= count1 * price1;
        totalprice+=s;

      }
      this.editForm.totalprice=totalprice;
      this.price3=this.editForm.totalprice;
      //console.log(this.editForm.totalprice);

    },
    //编辑==删除选择的药品
    editcancelSelect(medicineId){
      this.selectDrugList.forEach((item,index)=>{
        if(item.medicine.id==medicineId){
          this.selectDrugList.splice(index,1);
          this.editForm.totalprice=this.editForm.totalprice-item.sumPrice;
        }
        this.price3=this.editForm.totalprice;
      })
    },
    //编辑==取消编辑
    closeeditDeliverForm(){
      this.editFormVisiable=false;
    },
    //编辑==确定修改订单
    editDeliver(){
      if(this.selectDrugList.length<1){
        alert("请选择药品！");
        return;
      }
      this.$refs.editFormRef.validate((valid)=>{
        if(!valid){return};
        this.editForm.deliveryDetailVos=this.selectDrugList;
        this.$axios.post("/delivery/modify",this.editForm).then((res)=>{
          if(res.data.code==200){
            this.$message({
              message: res.data.msg,
              type: 'success',
              duration: 1000
            });
            this.initdeliveryVolIst();
          }else {
            this.$message({
              message: res.data.msg,
              type: 'success',
              duration: 1000
            });
          }
          this.editFormVisiable=false;
        });
      })
    },
    //选择IC卡
    handleChangeICCard(num){
      //console.log(num)
      //console.log(this.ICCard)
      for (let card of this.ICCard) {
        if (card.id===num) {
          this.balance=card.balance
        }
      }

    },
    //选择长者
    selectOlder(id, name) {
      this.balance=''
      this.selectDrugList=[];
      this.costPay=[]
      //console.log(this.addDeliveryForm.totalprice)
      //this.addDeliveryForm.olderId = id;
      this.addDeliveryForm.olderName = name;
      this.$set(this.addDeliveryForm,"olderId",id);
      this.$refs.addDeliveryFormRef.validateField('olderId');
      // this.editForm.olderId = id;
      // this.editForm.olderName = name;
      let sum=0;
      //查出长者IC卡
      let url = "/card/selectCardById/" + id;
      this.$axios.get(url).then((res) => {
        if (res.data.code == 200) {
          this.ICCard = res.data.data;
          //console.log(this.ICCard)
        } else {
          this.$message({
            message: res.data.msg,
            type: 'error',
            duration: 1000
          });
        }
      })
     // console.log(this.addDeliveryForm.totalprice)
      //查出扣费信息
      let urll = "/checkIn/selectRoomPayById/" + id;
      this.$axios.get(urll).then((res) => {
        if (res.data.code == 200) {
          let roomPay = res.data.data;
          sum+=parseInt(roomPay.price)
          //console.log(this.addDeliveryForm.totalprice)
          this.costPay.push(roomPay)
        } else {
          this.$message({
            message: res.data.msg,
            type: 'error',
            duration: 1000
          });
        }
      })

      let urlll = "/checkIn/selectCarePayById/" + id;
      this.$axios.get(urlll).then((res) => {
        if (res.data.code == 200) {
          let roomPay = res.data.data;
          sum+=parseInt(roomPay.price)
          this.costPay.push(roomPay)
          this.addDeliveryForm.totalprice=sum
         // console.log(sum)
          //console.log(this.costPay)
        } else {
          this.$message({
            message: res.data.msg,
            type: 'error',
            duration: 1000
          });
        }
      })


      this.innerOlderVisible = false;
    },
    //添加==删除出库订单中的药品
    cancelSelect(id){
      this.selectDrugList.forEach((item,index)=>{
        //console.log(item)
        if(item.id==id){
          this.selectDrugList.splice(index,1);
          this.addDeliveryForm.totalprice=this.addDeliveryForm.totalprice-item.price;
        }
        this.price2=this.addDeliveryForm.totalprice;
      })
    },
    //添加,编辑==选择药品，添加进去集合
    selectDrug(medicine) {
      for(let c of this.selectDrugList){
        if(c.id==medicine.id){
          this.innerDrugVisible = false;
          this.$message({
            message: '您已经添加过此项目',
            type: 'error',
            duration: 1000
          });
          return;
        }
      }
     // let deliveyrDetailVo={medicine:medicine,count: 1,sumPrice:medicine.saleprice};
      this.selectDrugList.push(medicine);
      //console.log(this.selectDrugList)
      this.addDeliveryForm.totalprice +=medicine.price;
      this.price2=this.addDeliveryForm.totalprice;
      this.editForm.totalprice +=medicine.saleprice;
      this.price3=this.editForm.totalprice;
      this.innerDrugVisible = false;
    },
    //添加==改变药品数量--价格小计,总计
    handleChange(deliveryDetailVo){
      //this.addDeliveryForm.totalprice=0;
      let totalprice=0;
      let price=deliveryDetailVo.medicine.saleprice;
      let count=deliveryDetailVo.count;
      let sumprice= price * count;
      for(let a of this.selectDrugList){
        if(deliveryDetailVo.medicine.id==a.medicine.id){
          a.sumPrice=sumprice;
        }

        let price1=a.medicine.saleprice;
        let count1=a.count;
        let s= count1 * price1;
        totalprice+=s;

      }
      this.addDeliveryForm.totalprice=totalprice;
      this.price2=this.addDeliveryForm.totalprice;
     // console.log(this.addDeliveryForm.totalprice);

    },
    //打开添加订单对话框
    openAddDialog() {
      this.addDeliveryFormVisible = true;
      this.ICCard=[]
      this.addDeliveryForm={};
      this.$set(this.addDeliveryForm,'saletime',new Date());
      this.selectDrugList=[];
      this.costPay=[]
      this.balance=''
    },
    //添加==关闭添加对话框(取消添加)订单
    closeAddDeliverForm() {
      this.costPay=[]
      this.balance=''
      this.addDeliveryForm={};
      this.selectDrugList=[];
      this.addDeliveryFormVisible = false;
    },
    //添加==确定添加订单
    addDeliver() {
      this.addDeliveryForm.cardId=this.ICCard.number
      console.log(this.addDeliveryForm.cardId)
      if (this.addDeliveryForm.cardId===undefined) {
        this.$message({
          message:"卡号不能为空",
          type: 'error',
          duration: 1000
        });
        return;
      }
      //console.log(this.addDeliveryForm)
      this.$confirm("确定添加入院收费吗？确认将直接从选择的IC卡扣款", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.$refs.addDeliveryFormRef.validate((valid)=>{
          if(!valid){return}
          this.addDeliveryForm.deliveryDetailVos=this.selectDrugList;
          this.$axios.post("/checkIn/insertCheckIn",this.addDeliveryForm).then((res)=>{
            if(res.data.code==200){
              this.$message({
                message: res.data.msg,
                type: 'success',
                duration: 1000
              });
              this.initdeliveryVolIst();
            }else {
              this.$message({
                message: res.data.msg,
                type: 'error',
                duration: 1000
              });
              return
            }
            this.addDeliveryFormVisible=false;
          });
        })

      }).catch(() => {
        this.$message({
          type: "info",
          message: "取消成功"
        })
      });
    },
    //打开出库对话框
    goDelivery(id, totalprice) {
      this.id = id;
      this.pay = totalprice;
      this.innerVisible = true;
    },
    //出库
    selectCard(number) {
      this.CardNumber = number;
      this.$confirm("你确定要用此卡消费出库吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.$axios.get("/delivery/gopay", {
          params: {
            id: this.id,
            pay: this.pay,
            CardNumber: this.CardNumber,
          }
        }).then((res) => {
          if (res.data.code == 200) {
            this.$message({
              message: res.data.msg,
              type: 'success',
              duration: 1000
            });
            this.innerVisible = false;
            this.initdeliveryVolIst();
            this.initCardList();
            this.initDrugList();
          } else {
            this.$message({
              message: res.data.msg,
              type: 'error',
              duration: 1000
            });
          }
        })
      }).catch(() => {
        this.CardNumber = "";

        this.$message({
          type: "info",
          message: "取消出库成功"
        })
      })
    },
    //作废
    cancelDelivery(id) {
      this.$confirm("确定要作废吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.$axios.get("/checkIn/cancelCheckIn/" + id).then((res) => {
          if (res.data.code == 200) {
            this.$message({
              message: res.data.msg,
              type: 'success',
              duration: 1000
            });

            this.initdeliveryVolIst();
            this.initCardList();
            this.initDrugList();
          } else {
            this.$message({
              message: res.data.msg,
              type: 'error',
              duration: 1000
            });
          }
        });
      }).catch(() => {
        this.$message({
          type: "info",
          message: "取消成功"
        })
      })
    },

    //查看订单详情
    searchDetail(deliveryvo) {
      this.detailTotalprice=deliveryvo.totalprice;
      this.detailoldername=deliveryvo.older.name;
      this.detailOrdernum=deliveryvo.ordernum;
      this.$axios.get("/delivery/detailById/" + deliveryvo.id).then((res) => {
        if (res.data.code == 200) {
          this.detailList = res.data.data;
          this.detailVisible = true;
        } else {
          this.$message({
            message: res.data.msg,
            type: 'error',
            duration: 1000
          });
        }
      })
    },
    handleSizeChange(newSize) {
      this.pageNum = 1;
      this.pageSize = newSize;
      this.initdeliveryVolIst();
    },
    handleCurrentChange(newPage) {
      this.pageNum = newPage;
      this.initdeliveryVolIst();
    },
    search() {
      this.pageNum = 1;
      this.initdeliveryVolIst();
    },

    initdeliveryVolIst() {
     // console.log(this.dateInterval)
      //console.log(this.status)
      this.$axios.get("/checkIn/selectCheckIn", {
        params: {
          now: this.pageNum,
          size: this.pageSize,
          status: this.status,
          name: this.oldername,
          beginDate:this.dateInterval[0],
          endDate:this.dateInterval[1]
        }
      }).then((res) => {
        if (res.data.code == 200) {
         // console.log(res.data.data.list)
          this.deliveryvoList = res.data.data.list;
          this.total = res.data.data.total;
          this.pageNum = res.data.data.pageNum;
          this.pageSize = res.data.data.pageSize;
        } else {
          this.$message({
            message: res.data.msg,
            type: 'error',
            duration: 1000
          });
        }
      })
    },
//查询ic卡
    initCardList() {
      this.$axios.get("/card/findAllCard", {
        params: {
          cardName: this.cardName
        }
      }).then((res) => {
        if (res.data.code == 200) {
          this.CardList = res.data.data;
        //  console.log(res.data.data);
        }
      })
    },

    tableRowClassName({rowIndex}) {
      if (rowIndex === 0) {
        return 'white-row'; // 第一行为白色
      } else if (rowIndex % 4 === 1) {
        return 'warning-row'; // 第二行和每隔三行后的行为绿色
      } else if (rowIndex % 2 === 0) {
        return ''; // 第二行和每隔三行后的行为绿色
      } else if (rowIndex % 3 === 2) {
        return 'white-row'; // 第三行和每隔三行后的行为白色
      } else {
        return 'success-row'; // 每隔三行后的行为黄色
      }
    },


    //改变长者条数查询
    olderSizeChange(size) {
      this.olderPageSize = size;
      this.olderPageNum = 1;
      this.initOlderList();
    },
    //改变长者页数查询
    olderCurrentChange(now) {
      this.olderPageNum = now;
      this.initOlderList();
    },
    //长者内置搜收框
    searchOlder() {
      this.olderPageNum = 1;
      this.initOlderList();
    },
    //初始化长者信息
    initOlderList() {
      let url = "/Older/list"
      this.$axios.get(url, {
        params: {
          name: this.olderName,
          now: this.olderPageNum,
          size: this.olderPageSize
        }
      }).then((res) => {
        if (res.data.code == 200) {
          this.olderList = res.data.data.list;
          this.olderPageNum = res.data.data.pageNum;
          this.olderPageSize = res.data.data.pageSize;
          this.olderTotal = res.data.data.total;
        } else {
          this.$message({
            message: res.data.msg,
            type: 'error',
            duration: 1000
          });
        }
      })
    },


    //选择药品-页码1
    drugHandleSizeChange(newSize) {
      this.drugpageNum = 1;
      this.drugpageSize = newSize;
      this.initDrugList();
    },
    //选择药品-页码2
    drugHandleCurrentChange(newPage) {
      this.drugpageNum = newPage;
      this.initDrugList();
    },
    //选择药品-搜素
    searchDrug() {
      this.drugpageNum = 1;
      this.initDrugList();
    },
    //选择其他收付款-查寻
    initDrugList() {
      this.$axios.get("/otherCost/selectOtherCost", {
        params: {
          now: this.drugpageNum,
          size: this.drugpageSize,
          drugname: this.drugname
        }
      }).then((res) => {
        if (res.data.code == 200) {
         // console.log(res.data.data.list)
          this.drugList = res.data.data.list;
          this.drugtotal = res.data.data.total;
          this.drugpageNum = res.data.data.pageNum;
          this.drugpageSize = res.data.data.pageSize;
        } else {
          this.$message({
            message: res.data.msg,
            type: 'error',
            duration: 1000
          });
        }
      })
    },
  },
  created() {
    this.initdeliveryVolIst();
    this.initCardList();
    this.initOlderList();
    this.initDrugList();
  },
}

</script>

<style scoped>
.input-with-select {
  background-color: #fff;
  color: #2d3a4b;
}

.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
